package com.ohuang.demo;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class MyFrameLayout extends FrameLayout {


    public MyFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyFrameLayout(@NonNull Context context) {
        this(context,null);
    }


    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);

    }

    private void init() {


    }



    @Override
    public void draw(@NonNull Canvas canvas) {

        super.draw(canvas);



    }

    @Override
    protected void dispatchDraw(@NonNull Canvas canvas) {
        // 获取 View 的宽度和高度
        int width = getWidth();
        int height = getHeight();
        var bitmap =Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas newCanvas =  new Canvas(bitmap);
        // 先绘制背景
        super.dispatchDraw(newCanvas);
        canvas.drawBitmap(bitmap, 0, 0, null);



    }

    @Override
    protected boolean drawChild(@NonNull Canvas canvas, View child, long drawingTime) {
        return super.drawChild(canvas, child, drawingTime);
    }

    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);

    }
}
